#define _CRT_SECURE_NO_WARNINGS
#include <iostream>

class Solution {
public:
    int triangleNumber(vector<int>& nums) {
        std::sort(nums.begin(), nums.end());

        int ret = 0, left = 0, right = 0;
        int max = nums.size() - 1;
        while (max >= 2)
        {
            left = 0, right = max - 1;
            while (left < right)
            {
                if (nums[left] + nums[right] > nums[max])
                {
                    ret += right - left;
                    right--;
                }
                else
                {
                    left++;
                }
            }
            max--;
        }

        return ret;

    }
};

int main()
{
	return 0;
}